/** FASSIT (Forms of Selective Attention in Intelligent Transportation Systems)
 * Computational Creativity and Digital Media
 * Cognitive and Media Systems Group
 * Centre for Informatics and Systems of the University of Coimbra (CISUC)
 *
 * Copyright (c) 2010-2013 University of Coimbra, Portugal
 * All rights reserved.
 */

package agent.DBManager;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import poi.Info.POI;
import poi.Info.POIwithSAMetrics;
import poi.Surprise.SurpriseDaysOff;
import poi.Surprise.SurprisePrice;
import poi.Surprise.SurpriseSchedule;
import poi.Uncertainty.UncertaintyDaysOff;
import poi.Uncertainty.UncertaintyPrice;
import poi.Uncertainty.UncertaintySchedule;
import agent.Context.Context;
import agent.Metrics.Surprise.FirstPoiSurprise;
import agent.Metrics.Surprise.PastSurpriseValues;
import agent.Metrics.Uncertainty.FirstPoiUncertainty;
import agent.Metrics.Uncertainty.PastUncertaintyValues;

import com.mysql.jdbc.Connection;

import functionsVariables.MySQLConnection;

/**
 * This class defines all the low level methods to communicate with the mysql
 * database
 * 
 * @author Hernani Costa
 * @version 0.2 date: 27/01/2013
 */
public class AgentDBConnection {

	private MySQLConnection dbconnection;
	private Connection connection;

	/**
	 * ------------------------------------------------------------------------
	 * Constructor class
	 * ------------------------------------------------------------------------
	 */
	public AgentDBConnection() {
		dbconnection = MySQLConnection.getInstance();
	}

	/**
	 * ------------------------------------------------------------------------
	 * Deletes the stored Agent Knowledge from the tables 'ex3_agentX_model'
	 * and 'ex3_agentX_SAValues'
	 * ------------------------------------------------------------------------
	 */
	public void deleteAgentKnowledge() {
		try {
			connection = dbconnection.openConnection();
			String query1 = "DELETE FROM  ex3_agentX_model";

			PreparedStatement s = connection.prepareStatement(query1);
			s.executeUpdate();

			String query2 = "DELETE FROM  ex3_agentX_SAValues";
			s = connection.prepareStatement(query2);
			s.executeUpdate();
			s.close();
			dbconnection.closeConnection();
		} catch (SQLException e) {
			e.printStackTrace();
			dbconnection.closeConnection();
		}
		// CREATE TABLE recipes_new LIKE production.recipes;
		// INSERT recipes_new SELECT * FROM production.recipes;
	}

	/**
	 * Saves all the POIs visited by the agent (in a specific Context) and the
	 * resulted Surprise and Uncertainty values for each POI
	 * 
	 * @param pois
	 *            - POIs visited by the Agent
	 * @param context
	 *            - Context
	 * @return true if successfully saved, false if not
	 */
	public boolean savePOIs(ArrayList<POI> pois, Context context) {
		/*
		 * CREATE TABLE `POIsDB`.`ex3_agentX_model` (`id` INT(11) NOT NULL
		 * AUTO_INCREMENT, `poiID` INT(11) NOT NULL, `poiName` VARCHAR(60) NULL
		 * DEFAULT NULL, `poiLat` FLOAT(10,6) NULL DEFAULT NULL, `poiLng`
		 * FLOAT(10,6) NULL DEFAULT NULL, `poiPrice` VARCHAR(30) NULL DEFAULT
		 * NULL, `poiSchedule` VARCHAR(1000) NULL DEFAULT NULL, `poiDayOff`
		 * VARCHAR(100) NULL DEFAULT NULL, `poiCatID` INT(11) NULL DEFAULT NULL,
		 * `poiCatName` VARCHAR(30) NULL DEFAULT NULL, `poiSubCatID` INT(11)
		 * NULL DEFAULT NULL, `poiSubCatName` VARCHAR(30) NULL DEFAULT NULL,
		 * `agentDistanceTOpoi_string` VARCHAR(30) NULL DEFAULT NULL,
		 * `agentDistanceTOpoi_int` FLOAT(10,6) NULL DEFAULT NULL,
		 * `agentTimeOfDay` FLOAT(10,6) NULL DEFAULT NULL, `agentDayOfWeek`
		 * VARCHAR(30) NULL DEFAULT NULL, `agentGoal` VARCHAR(30) NULL DEFAULT
		 * NULL, `sTOcategory` FLOAT(10,6) NULL DEFAULT NULL, `sTOsubCategory`
		 * FLOAT(10,6) NULL DEFAULT NULL, `sTOprice` FLOAT(10,6) NULL DEFAULT
		 * NULL, `sTOdayOff` FLOAT(10,6) NULL DEFAULT NULL, `sTOschedule`
		 * FLOAT(10,6) NULL DEFAUL
		 */
		int poiID, poiCatID, poiSubCatID;
		double distanceBetweenUserPOI;
		String poiCatName, poiSubCatName, poiName, poiPrice, poiSchedule, poiDaysOff, agentDistanceTOpoi_string;
		double poiLat, poiLng;
		String agentTimeOfDay = context.getTimeOfDay();
		String agentDayOfWeek = context.getDayOfWeek();
		int runID = context.getRunID();
		String agentGoal = context.getGoal();
		double sTOcategory, sTOsubCategory, sTOprice, sTOdayOff, sTOschedule, sAverage;
		double uTOcategory, uTOsubCategory, uTOprice, uTOdayOff, uTOschedule, uAverage;

		connection = dbconnection.openConnection();
		try {
			PreparedStatement s = null;

			for (POI poi : pois) {
				poiID = poi.getPoiID();
				poiCatID = poi.getCategory().getCategoryID();
				poiSubCatID = poi.getSubCategory().getSubCategoryID();
				poiCatName = poi.getCategory().getCategoryName();
				poiSubCatName = poi.getSubCategory().getSubCategoryName();
				agentDistanceTOpoi_string = poi.getAgentDistanceTOpoi_string();
				distanceBetweenUserPOI = context.getLocation().getGeoPoint()
						.getDistanceMeters(poi.getLocation().getGeoPoint());
				poiName = poi.getPoiName();
				poiPrice = poi.getPrice().getAveragePrice();
				poiSchedule = poi.getDaysOn().getStringDaysOn();
				poiDaysOff = poi.getDaysOff().getStringDaysOff();
				poiLat = poi.getLocation().getLatitude();
				poiLng = poi.getLocation().getLongitude();
				
				sTOcategory = poi.getSurpriseTOcategory();
				sTOsubCategory = poi.getSurpriseTOsubCategory();
				sTOprice = poi.getSurpriseTOprice();
				sTOdayOff = poi.getSurpriseTOdayOff();
				sTOschedule = poi.getSurpriseTOschedule();
				sAverage = poi.getSurpriseAverage();
				
				uTOcategory = poi.getUncertaintyTOcategory();
				uTOsubCategory = poi.getUncertaintyTOsubCategory();
				uTOprice = poi.getUncertaintyTOprice();
				uTOdayOff = poi.getUncertaintyTOdayOff();
				uTOschedule = poi.getUncertaintyTOschedule();
				uAverage = poi.getUncertaintyAverage();

				s = connection
						.prepareStatement("INSERT INTO ex3_agentX_model ("
								+ "poiID, "
								+ "poiName,"
								+ "poiLat,"
								+ "poiLng,"
								+ "poiPrice,"
								+ "poiSchedule,"
								+ "poiDayOff,"
								+ "poiCatID, "
								+ "poiCatName,"
								+ "poiSubCatID, "
								+ "poiSubCatName, "

								+ "agentDistanceTOpoi_string,"
								+ "agentDistanceTOpoi_int,"
								+ "agentTimeOfDay,"
								+ "agentDayOfWeek,"
								+ "agentGoal,"

								+ "sTOcategory,"
								+ "sTOsubCategory,"
								+ "sTOprice,"
								+ "sTOdayOff,"
								+ "sTOschedule,"
								+ "sAverage,"

								+ "uTOcategory,"
								+ "uTOsubCategory,"
								+ "uTOprice,"
								+ "uTOdayOff,"
								+ "uTOschedule,"
								+ "uAverage,"

								+ "runID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

				s.setInt(1, poiID);
				s.setString(2, poiName);
				s.setDouble(3, poiLat);
				s.setDouble(4, poiLng);
				s.setString(5, poiPrice);
				s.setString(6, poiSchedule);
				s.setString(7, poiDaysOff);
				s.setInt(8, poiCatID);
				s.setString(9, poiCatName);
				s.setInt(10, poiSubCatID);
				s.setString(11, poiSubCatName);
				s.setString(12, agentDistanceTOpoi_string);
				s.setDouble(13, distanceBetweenUserPOI);
				s.setString(14, agentTimeOfDay);
				s.setString(15, agentDayOfWeek);
				s.setString(16, agentGoal);
				s.setDouble(17, sTOcategory);
				s.setDouble(18, sTOsubCategory);
				s.setDouble(19, sTOprice);
				s.setDouble(20, sTOdayOff);
				s.setDouble(21, sTOschedule);
				s.setDouble(22, sAverage);
				
				s.setDouble(23, uTOcategory);
				s.setDouble(24, uTOsubCategory);
				s.setDouble(25, uTOprice);
				s.setDouble(26, uTOdayOff);
				s.setDouble(27, uTOschedule);
				s.setDouble(28, uAverage);
				
				s.setInt(29, runID);

				s.executeUpdate();
				s.close();
			}
			dbconnection.closeConnection();
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
			dbconnection.closeConnection();
			return false;
		}
	}

	/**
	 * Saves the Selective Attention values for all the parameters (Price,
	 * DaysOff and Schedule)
	 * 
	 * @param poiWithSelectiveAttentionValues
	 *            - POI with the Selective Attention values
	 * @param context
	 *            - Context
	 * @return true if successfully saved, false if not
	 */
	public boolean saveSAValues(POIwithSAMetrics poiWithSelectiveAttentionValues, Context context) {
		/*
		 * CREATE TABLE `POIsDB`.`ex3_agentX_SAValues` (`id` INT(11) NOT NULL
		 * AUTO_INCREMENT, `poiID` INT(11) NOT NULL, `s_price_cheap` DOUBLE(10,6)
		 * NULL, `s_price_average` DOUBLE(10,6) NULL, `s_price_expensive`
		 * DOUBLE(10,6) NULL, `s_schedule_morning` DOUBLE(10,6) NULL,
		 * `s_schedule_afternoon` DOUBLE(10,6) NULL, `s_schedule_night` DOUBLE(10,6)
		 * NULL, `s_dayoff_sunday` DOUBLE(10,6) NULL, `s_dayoff_monday` DOUBLE(10,6)
		 * NULL, `s_dayoff_tuesday` DOUBLE(10,6) NULL, `s_dayoff_wednesday`
		 * DOUBLE(10,6) NULL, `s_dayoff_thursday` DOUBLE(10,6) NULL,
		 * `s_dayoff_friday` DOUBLE(10,6) NULL, `s_dayoff_saturday` DOUBLE(10,6)
		 * NULL, `u_price_cheap` DOUBLE(10,6) NULL, `u_price_average` DOUBLE(10,6)
		 * NULL, `u_price_expensive` DOUBLE(10,6) NULL, `u_schedule_morning`
		 * DOUBLE(10,6) NULL, `u_schedule_afternoon` DOUBLE(10,6) NULL,
		 * `u_schedule_night` DOUBLE(10,6) NULL, `u_dayoff_sunday` DOUBLE(10,6)
		 * NULL, `u_dayoff_monday` DOUBLE(10,6) NULL, `u_dayoff_tuesday`
		 * DOUBLE(10,6) NULL, `u_dayoff_wednesday` DOUBLE(10,6) NULL, `u_dayof...
		 */
		//System.out.println("POI TO BE STORED:" + poiWithSelectiveAttentionValues.to_String());
		int poiID;
		int runID = context.getRunID();
		String agentGoal = context.getGoal();
		double s_price_cheap, s_price_average, s_price_expensive, s_schedule_morning, s_schedule_afternoon, s_schedule_night, s_dayoff_sunday, s_dayoff_monday, s_dayoff_tuesday, s_dayoff_wednesday, s_dayoff_thursday, s_dayoff_friday, s_dayoff_saturday;
		double u_price_cheap, u_price_average, u_price_expensive, u_schedule_morning, u_schedule_afternoon, u_schedule_night, u_dayoff_sunday, u_dayoff_monday, u_dayoff_tuesday, u_dayoff_wednesday, u_dayoff_thursday, u_dayoff_friday, u_dayoff_saturday;
		POI poi = null;

		connection = dbconnection.openConnection();
		try {
			PreparedStatement s = null;

			poi = poiWithSelectiveAttentionValues.getPoi();

			poiID = poi.getPoiID();

			// Surprise Values
			s_price_cheap = poiWithSelectiveAttentionValues.getSurprisePrice()
					.getCheap();
			s_price_average = poiWithSelectiveAttentionValues
					.getSurprisePrice().getAverage();
			s_price_expensive = poiWithSelectiveAttentionValues
					.getSurprisePrice().getExpensive();
			s_schedule_morning = poiWithSelectiveAttentionValues
					.getSurpriseSchedule().getMorning();
			s_schedule_afternoon = poiWithSelectiveAttentionValues
					.getSurpriseSchedule().getAfternoon();
			s_schedule_night = poiWithSelectiveAttentionValues
					.getSurpriseSchedule().getNight();
			s_dayoff_sunday = poiWithSelectiveAttentionValues
					.getSurpriseDayOff().getSunday();
			s_dayoff_monday = poiWithSelectiveAttentionValues
					.getSurpriseDayOff().getMonday();
			s_dayoff_tuesday = poiWithSelectiveAttentionValues
					.getSurpriseDayOff().getTuesday();
			s_dayoff_wednesday = poiWithSelectiveAttentionValues
					.getSurpriseDayOff().getWednesday();
			s_dayoff_thursday = poiWithSelectiveAttentionValues
					.getSurpriseDayOff().getThursday();
			s_dayoff_friday = poiWithSelectiveAttentionValues
					.getSurpriseDayOff().getFriday();
			s_dayoff_saturday = poiWithSelectiveAttentionValues
					.getSurpriseDayOff().getSaturday();

			// Uncertainty Values
			u_price_cheap = poiWithSelectiveAttentionValues
					.getUncertaintyPrice().getCheap();
			u_price_average = poiWithSelectiveAttentionValues
					.getUncertaintyPrice().getAverage();
			u_price_expensive = poiWithSelectiveAttentionValues
					.getUncertaintyPrice().getExpensive();
			u_schedule_morning = poiWithSelectiveAttentionValues
					.getUncertaintySchedule().getMorning();
			u_schedule_afternoon = poiWithSelectiveAttentionValues
					.getUncertaintySchedule().getAfternoon();
			u_schedule_night = poiWithSelectiveAttentionValues
					.getUncertaintySchedule().getNight();
			u_dayoff_sunday = poiWithSelectiveAttentionValues
					.getUncertaintyDayOff().getSunday();
			u_dayoff_monday = poiWithSelectiveAttentionValues
					.getUncertaintyDayOff().getMonday();
			u_dayoff_tuesday = poiWithSelectiveAttentionValues
					.getUncertaintyDayOff().getTuesday();
			u_dayoff_wednesday = poiWithSelectiveAttentionValues
					.getUncertaintyDayOff().getWednesday();
			u_dayoff_thursday = poiWithSelectiveAttentionValues
					.getUncertaintyDayOff().getThursday();
			u_dayoff_friday = poiWithSelectiveAttentionValues
					.getUncertaintyDayOff().getFriday();
			u_dayoff_saturday = poiWithSelectiveAttentionValues
					.getUncertaintyDayOff().getSaturday();

			s = connection
					.prepareStatement("INSERT INTO ex3_agentX_SAValues ("
							+ "poiID, "
							+ "s_price_cheap,"
							+ "s_price_average,"
							+ "s_price_expensive,"
							+ "s_schedule_morning,"
							+ "s_schedule_afternoon,"
							+ "s_schedule_night,"
							+ "s_dayoff_sunday, "
							+ "s_dayoff_monday,"
							+ "s_dayoff_tuesday, "
							+ "s_dayoff_wednesday, "
							+ "s_dayoff_thursday,"
							+ "s_dayoff_friday,"
							+ "s_dayoff_saturday,"

							+ "u_price_cheap,"
							+ "u_price_average,"
							+ "u_price_expensive,"
							+ "u_schedule_morning,"
							+ "u_schedule_afternoon,"
							+ "u_schedule_night,"
							+ "u_dayoff_sunday, "
							+ "u_dayoff_monday,"
							+ "u_dayoff_tuesday, "
							+ "u_dayoff_wednesday, "
							+ "u_dayoff_thursday,"
							+ "u_dayoff_friday,"
							+ "u_dayoff_saturday,"
							+ "runID,"
							+ "agentGoal) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

			s.setInt(1, poiID);
			s.setDouble(2, s_price_cheap);
			s.setDouble(3, s_price_average);
			s.setDouble(4, s_price_expensive);
			s.setDouble(5, s_schedule_morning);
			s.setDouble(6, s_schedule_afternoon);
			s.setDouble(7, s_schedule_night);
			s.setDouble(8, s_dayoff_sunday);
			s.setDouble(9, s_dayoff_monday);
			s.setDouble(10, s_dayoff_tuesday);
			s.setDouble(11, s_dayoff_wednesday);
			s.setDouble(12, s_dayoff_thursday);
			s.setDouble(13, s_dayoff_friday);
			s.setDouble(14, s_dayoff_saturday);

			s.setDouble(15, u_price_cheap);
			s.setDouble(16, u_price_average);
			s.setDouble(17, u_price_expensive);
			s.setDouble(18, u_schedule_morning);
			s.setDouble(19, u_schedule_afternoon);
			s.setDouble(20, u_schedule_night);
			s.setDouble(21, u_dayoff_sunday);
			s.setDouble(22, u_dayoff_monday);
			s.setDouble(23, u_dayoff_tuesday);
			s.setDouble(24, u_dayoff_wednesday);
			s.setDouble(25, u_dayoff_thursday);
			s.setDouble(26, u_dayoff_friday);
			s.setDouble(27, u_dayoff_saturday);

			s.setDouble(28, runID);
			s.setString(29, agentGoal);

			s.executeUpdate();
			s.close();

			dbconnection.closeConnection();
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
			dbconnection.closeConnection();
			return false;
		}
	}

	/**
	 * For a specific Goal, returns all the Surprise values for all the POIs
	 * visited by the Agent in the past
	 * 
	 * @param context
	 *            - Current context
	 * @return all the Surprise values for all the POIs visited by the Agent in
	 *         the past
	 */
	@SuppressWarnings("null")
	public PastSurpriseValues getSurpriseValuesForGoal(Context context) {
		boolean flag = true;
		Statement stt = null;
		ResultSet rs = null;
		PastSurpriseValues surprise = new PastSurpriseValues();
		SurpriseDaysOff sDayOff = null;
		SurprisePrice sPrice = null;
		SurpriseSchedule sSchedule = null;
		double price_cheap, price_average, price_expensive, schedule_morning, schedule_afternoon, schedule_night, dayoff_sunday, dayoff_monday, dayoff_tuesday, dayoff_wednesday, dayoff_thursday, dayoff_friday, dayoff_saturday;

		int id, poiID, runID;
		String agentGoal = "";
		//System.out.println("GOAL::"+context.getGoal());
		try {
			connection = dbconnection.openConnection();
			stt = connection.createStatement();
			rs = stt.executeQuery("SELECT * FROM ex3_agentX_SAValues WHERE agentGoal='"
					+ context.getGoal() + "'");

			while (rs.next()) {
				id = rs.getInt(1);
				poiID = rs.getInt(2);
				price_cheap = rs.getDouble(3);
				price_average = rs.getDouble(4);
				price_expensive = rs.getDouble(5);
				schedule_morning = rs.getDouble(6);
				schedule_afternoon = rs.getDouble(7);
				schedule_night = rs.getDouble(8);
				dayoff_sunday = rs.getDouble(9);
				dayoff_monday = rs.getDouble(10);
				dayoff_tuesday = rs.getDouble(11);
				dayoff_wednesday = rs.getDouble(12);
				dayoff_thursday = rs.getDouble(13);
				dayoff_friday = rs.getDouble(14);
				dayoff_saturday = rs.getDouble(15);
				runID = rs.getInt(16);
				agentGoal = rs.getString(17);

				sDayOff = new SurpriseDaysOff(dayoff_sunday, dayoff_monday,
						dayoff_tuesday, dayoff_wednesday, dayoff_thursday,
						dayoff_friday, dayoff_saturday);
				sPrice = new SurprisePrice(price_cheap, price_average,
						price_expensive);
				sSchedule = new SurpriseSchedule(schedule_morning,
						schedule_afternoon, schedule_night);
				surprise.addSurprise(sDayOff, sPrice, sSchedule);
				flag = false;

			}
			dbconnection.closeConnection();
		} catch (SQLException e) {
			e.printStackTrace();
			dbconnection.closeConnection();
		}
		// In the training process we do not have yet any entry in the table
		// 'ex3_agentX_surpriseValues', so we need to create a the 'FIRSTPOI'
		if (flag) {
			FirstPoiSurprise firstPOI = new FirstPoiSurprise();
			//System.out.println("[AgentDBConnection] First POI from Uncertainty: " + firstPOI.to_String());
			surprise.addSurprise(firstPOI.getSurpriseDaysOff(),
					firstPOI.getSurprisePrice(), firstPOI.getSurpriseSchedule());

		}

		return surprise;
	}

	
	/**
	 * For a specific Goal, returns all the Uncertainty values for all the POIs
	 * visited by the Agent in the past
	 * 
	 * @param context
	 *            - Current context
	 * @return all the Uncertainty values for all the POIs visited by the Agent in
	 *         the past
	 */
	@SuppressWarnings("null")
	public PastUncertaintyValues getUncertaintyValuesForGoal(Context context) {
		boolean flag = true;
		Statement stt = null;
		ResultSet rs = null;
		PastUncertaintyValues uncertainty = new PastUncertaintyValues();
		UncertaintyDaysOff uDayOff = null;
		UncertaintyPrice uPrice = null;
		UncertaintySchedule uSchedule = null;
		double price_cheap, price_average, price_expensive, schedule_morning, schedule_afternoon, schedule_night, dayoff_sunday, dayoff_monday, dayoff_tuesday, dayoff_wednesday, dayoff_thursday, dayoff_friday, dayoff_saturday;

		int id, poiID, runID;
		String agentGoal = "";

		try {
			connection = dbconnection.openConnection();
			stt = connection.createStatement();
			rs = stt.executeQuery("SELECT * FROM ex3_agentX_SAValues WHERE agentGoal='"
					+ context.getGoal() + "'");

			while (rs.next()) {
				id = rs.getInt(1);
				poiID = rs.getInt(2);
				price_cheap = rs.getDouble(3);
				price_average = rs.getDouble(4);
				price_expensive = rs.getDouble(5);
				schedule_morning = rs.getDouble(6);
				schedule_afternoon = rs.getDouble(7);
				schedule_night = rs.getDouble(8);
				dayoff_sunday = rs.getDouble(9);
				dayoff_monday = rs.getDouble(10);
				dayoff_tuesday = rs.getDouble(11);
				dayoff_wednesday = rs.getDouble(12);
				dayoff_thursday = rs.getDouble(13);
				dayoff_friday = rs.getDouble(14);
				dayoff_saturday = rs.getDouble(15);
				runID = rs.getInt(16);
				agentGoal = rs.getString(17);

				uDayOff = new UncertaintyDaysOff(dayoff_sunday, dayoff_monday,
						dayoff_tuesday, dayoff_wednesday, dayoff_thursday,
						dayoff_friday, dayoff_saturday);
				uPrice = new UncertaintyPrice(price_cheap, price_average,
						price_expensive);
				uSchedule = new UncertaintySchedule(schedule_morning,
						schedule_afternoon, schedule_night);
				uncertainty.addUncertainty(uDayOff, uPrice, uSchedule);
				flag = false;

			}
			dbconnection.closeConnection();
		} catch (SQLException e) {
			e.printStackTrace();
			dbconnection.closeConnection();
		}
		// In the training process we do not have yet any entry in the table
		// 'ex3_agentX_surpriseValues', so we need to create a the 'FIRSTPOI'
		if (flag) {
			FirstPoiUncertainty firstPOI = new FirstPoiUncertainty();
			//System.out.println("[AgentDBConnection] First POI from Uncertainty: " + firstPOI.to_String());
			
			uncertainty.addUncertainty(firstPOI.getUncertaintyDaysOff(),
					firstPOI.getUncertaintyPrice(), firstPOI.getUncertaintySchedule());

		}

		return uncertainty;
	}
	
	/**
	 * ------------------------------------------------------------------------
	 * Used to provide an example that exercises the functionality of the class.
	 * ------------------------------------------------------------------------
	 * 
	 * @param args
	 */
	public static void main(String args[]) {
		// creating a POI
		// ArrayList<POI> pois = new ArrayList<POI>();
		// masterAgent.DBmanager.DBConnection s = new
		// masterAgent.DBmanager.DBConnection();
		// pois.add(s.getPOI(2114795));
		// pois.add(s.getPOI(7540801));
		// Context c = new Context(new Location(8.2, 0.3), "morning", "cenas",
		// new Goal("party"), 100, 1);
		//
		// AgentDBConnection agent = new AgentDBConnection();
		// // agent.savePOIs(pois, c);
		//
		// agent.getPOIsNearLocation(new Goal("party"));

	}

	// CREATE TABLE `POIsDB`.`ex3_agentX_surpriseValues` (
	// `id` INT NOT NULL AUTO_INCREMENT ,
	// `poiID` INT NOT NULL ,
	// `price_cheap` DOUBLE NULL ,
	// `price_average` DOUBLE NULL ,
	// `price_expensive` DOUBLE NULL ,
	// `schedule_morning` DOUBLE NULL ,
	// `schedule_afternoon` DOUBLE NULL ,
	// `schedule_night` DOUBLE NULL ,
	// `dayoff_sunday` DOUBLE NULL ,
	// `dayoff_monday` DOUBLE NULL ,
	// `dayoff_tuesday` DOUBLE NULL ,
	// `dayoff_wednesday` DOUBLE NULL ,
	// `dayoff_thusday` DOUBLE NULL ,
	// `dayoff_friday` DOUBLE NULL ,
	// `dayoff_saturday` DOUBLE NULL ,
	// `runID` INT NULL ,
	// PRIMARY KEY ( `id` )
	// ) ENGINE = MYISAM ;

}
